<?php

// 第三方提现通知回调控制器

namespace app\api\controller;

use app\api\controller\Base;
use app\api\model\PaymentWithdrawalApi;
use think\facade\Response;

class Wnotify extends Base
{

    /**
     * 第三方付易通提现通知
     */
    public function fuyitong()
    {
        try {
            if ($this->request->has('status') && $this->request->has('sn')) {
                $order_id = $this->request->param('sn');              // 平台订单号
                $cash = $this->request->param('amount');              // 金额              
                $other_status = $this->request->param('status');      // 第三方状态    
                $other_order_id = $this->request->param('sn');        // 第三方订单号 
                $notify_param = input();                              // 通知参数 
                switch ($other_status) {
                    case '1':
                        $status = 2;  // 成功
                        break;
                    case '2':
                        $status = 3;  // 失败
                        break;
                    default:
                        return ['code' => 999, 'msg' => '404'];
                }
                // 实例化代付订单模型
                $payment_obj = new PaymentWithdrawalApi();
                $resdata = $payment_obj->notifyAbout($order_id, $notify_param, $cash, $status, $other_order_id, 'fuyitong', false, false, true);
                if ($resdata == 'success') {
                    return Response::create('success', 'html');
                }
            }
            return ['code' => 999, 'msg' => '404'];
        } catch (\Exception $e) {
            // payment_log(130000, input(), $e->getMessage(), false);
            abort(404, '页面不存在');
        }
    }
}
